import tensorflow as tf
import keras
a = tf.constant([[1, 1, 1, 1], [0, 0, 0, 0], [1, 0, 1, 0]])  # 3 * 4
b = tf.constant([[[0.1, 0.6, 0.3], [0.3, 0.1, 0.6], [0.2, 0.2, 0.6], [0.4, 0.5, 0.1]],
                 [[0.1, 0.6, 0.3], [0.3, 0.1, 0.6], [0.2, 0.2, 0.6], [0.4, 0.5, 0.1]],
                 [[0.1, 0.6, 0.3], [0.3, 0.1, 0.6], [0.2, 0.2, 0.6], [0.4, 0.5, 0.1]]
                 ])     # 3 * 4 * 3
print(keras.losses.sparse_categorical_crossentropy(a, b))
print(tf.reduce_mean(tf.reduce_mean(keras.losses.sparse_categorical_crossentropy(a, b), axis=-1), axis=-1))
print("a")
c = keras.losses.sparse_categorical_crossentropy(a, b)
a = tf.cast(a, tf.float32)
print(a*c)

print(tf.reduce_sum(a*c))
print(tf.reduce_sum(a))
print(tf.reduce_sum(a*c)/tf.reduce_sum(a))
print(tf.reduce_mean(tf.multiply(a,c), axis=-1))
print(tf.reduce_mean(tf.multiply(a,c)))
print(tf.reduce_mean(tf.reduce_mean(tf.multiply(a,c), axis=-1)))
